
package sg.edu.nus.iss.cats.dataaccess.mysql;

import sg.edu.nus.iss.cats.dataaccess.*;
import java.sql.*;

public class SequenceObjectHandler implements ObjectHandler {

    public String getTableName () {
        return DBConstants.sequences;
    }

    public String getKeyParameterConstraint () {
        return  DBConstants.seq_name + "=?";
    }

    public void setKeyParameters (PreparedStatement statement, Object obj)
                   throws SQLException, DAOException {
        SequenceInfo info = (SequenceInfo) obj;
        statement.setString (1, info.getName());
    }

    public Object retrieveObject (ResultSet results)
                   throws SQLException, DAOException {
        SequenceInfo obj = new SequenceInfo ();
        obj.setName (results.getString(DBConstants.seq_name));
        obj.setLastValue (results.getInt(DBConstants.last_value));
        return obj;
    }

    public void insertKeys (ResultSet results, Object obj)
                   throws SQLException, DAOException {
        SequenceInfo info = (SequenceInfo) obj;
        results.updateString (DBConstants.seq_name, info.getName());
    }

    public void updateObject (ResultSet results,  Object obj)
                   throws SQLException, DAOException {
        SequenceInfo info = (SequenceInfo) obj;
        results.updateInt (DBConstants.last_value, info.getLastValue());
    }

    public void completeObjectRetrieve (Object obj) throws DAOException {
    }

    public Object[] getObjectArray (int length) {
        return new SequenceInfo [length];
    }
}